var http = require('../http');
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        mUiEboxAccount: cc.EditBox,
        mUiEboxPwd: cc.EditBox,
        mTxtTip: cc.Label,
    },

    // use this for initialization
    onLoad: function () {

    },

    onAccountLogin: function() {
    	var account = this.mUiEboxAccount.string;
    	var password = this.mUiEboxPwd.string;
    	http.sendAccountLogin({account: account, password: password}, this._loginCallback.bind(this))
    },

    _loginCallback: function(msg){
    	console.log(msg);
    	this.mTxtTip.string = msg.errmsg;
    	if (msg.errcode == 0) {
    		//登陆成功;
    		this.node.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function() {
    			cc.director.loadScene('hall');
    		})));
    	}
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
}); 